//
//  HWShuRuTankuanView.m
//  HWPromoteProjectAPP
//
//  Created by 陈道斌 on 2020/3/11.
//  Copyright © 2020 陈道斌. All rights reserved.
//

#import "HWShuRuTankuanView.h"

@interface HWShuRuTankuanView()<UITextFieldDelegate>
@property(strong,nonatomic) UIView *grayView;
@property(strong,nonatomic) UIView *fenxiangView;

@end

@implementation HWShuRuTankuanView

-(instancetype)initWithFrame:(CGRect)frame {
    
    
    if (self = [super initWithFrame:frame]) {
        // 添加灰色背景
        [self addgrayView];
        
         [self setupUI];
    }
    
    return  self;
    
}

// 添加灰色View
-(void)addgrayView {
    
    self.grayView = [[UIView alloc]init];
    self.grayView.frame  = CGRectMake(0,0, kScreenW, kScreenH);
    
    self.grayView.backgroundColor =  RGB(51, 51, 51);
    self.grayView.alpha = 0.6;
    [self addSubview:self.grayView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapView:)];
    //  tap.delegate = self;
    [self.grayView addGestureRecognizer:tap];
    
    
    
    
}


//  设置UI
- (void)setupUI {
    
    
    
    self.fenxiangView = [[UIView alloc]initWithFrame:CGRectMake(20, (kScreenH-229)/2, kScreenW-40, 229)];
    self.fenxiangView.backgroundColor =  [UIColor whiteColor];
    self.fenxiangView.layer.cornerRadius = 8;
    
    self.fenxiangView.layer.masksToBounds = YES;

    [self addSubview:self.fenxiangView];
    
    

     UILabel *zhanghaoLabel  = [[UILabel alloc]initWithFrame:CGRectMake(20, 20, 300, 17)];
     zhanghaoLabel.text = @"支付宝账号";
     zhanghaoLabel.textAlignment =  NSTextAlignmentLeft;
     zhanghaoLabel.textColor = RGB(68, 68, 68);
     zhanghaoLabel.font = [UIFont systemFontOfSize:12];
    self.miashuLabel = zhanghaoLabel;
     [self.fenxiangView  addSubview:zhanghaoLabel];

    
 
      UITextField *textfeild1 = [[UITextField alloc]initWithFrame:CGRectMake(20, zhanghaoLabel.bottom+4,kScreenW-80 , 44)];
      textfeild1.placeholder = @"请输入支付宝账号";
   //  textfeild1.secureTextEntry = YES;
     // textfeild1.keyboardType = UIKeyboardTypeDecimalPad;
      textfeild1.textColor = RGB(68, 68, 68);
      textfeild1.font = [UIFont systemFontOfSize:14];
      textfeild1.backgroundColor = RGB(245, 245, 252);
      textfeild1.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 12, 44)];
      textfeild1.leftViewMode = UITextFieldViewModeAlways;
      textfeild1.layer.cornerRadius =  2;
      textfeild1.layer.masksToBounds = YES;
      self.miaoshutexefeild = textfeild1;
    self.miaoshutexefeild.delegate = self;
    
      [self.fenxiangView addSubview:textfeild1];
    
      
         UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
          button.frame = CGRectMake(20,self.miaoshutexefeild.bottom+30, kScreenW-80, 44);
         // [button setImage:[UIImage imageNamed:@"fanhuibaiseanniu_ico"] forState:UIControlStateNormal];
           [button setTitle:@"完成" forState:UIControlStateNormal];
          button.backgroundColor = RGB(85, 89, 234);
          [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
          [button addTarget:self action:@selector(buttonTap) forControlEvents:UIControlEventTouchUpInside];
          button.layer.cornerRadius = 2;
          button.layer.masksToBounds = YES;
         [self.fenxiangView addSubview:button];
          
          UIButton *quxiaobutton = [UIButton buttonWithType:UIButtonTypeCustom];
          quxiaobutton.frame = CGRectMake(20,button.bottom+10, kScreenW-80, 44);
              // [button setImage:[UIImage imageNamed:@"fanhuibaiseanniu_ico"] forState:UIControlStateNormal];
          [quxiaobutton setTitle:@"取消" forState:UIControlStateNormal];
          quxiaobutton.backgroundColor = RGB(238, 238, 238);
        [quxiaobutton setTitleColor:RGB(68, 68, 68) forState:UIControlStateNormal];
               [quxiaobutton addTarget:self action:@selector(quxiaoBut) forControlEvents:UIControlEventTouchUpInside];
            quxiaobutton.layer.cornerRadius = 2;
               quxiaobutton.layer.masksToBounds = YES;
              [self.fenxiangView addSubview:quxiaobutton];
               
    
    
    
    
    
    
    
    
    
    
    
}






- (void)tapView:(UITapGestureRecognizer *)touch {
    
    [touch.view.superview removeFromSuperview];
    //   [[NSNotificationCenter defaultCenter] postNotificationName:@"notifyName1" object:nil];
    
    
}




#pragma mark ----------- 点击完成按钮
- (void)buttonTap {
    
    
    if (!(self.miaoshutexefeild.text.length > 0)) {
        [MBProgressHUD showError:@"内容不能为空"];
    }
    
    [self removeFromSuperview];
    
    [self.miaoshutexefeild resignFirstResponder];
    
    
    
    
    
    
             [MBProgressHUD showMessage:@"正在修改"];
            
             NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
             NSString *uid =  [HWLocallyStoredData getLoginUserID];
           NSString *wenneiStr = self.miaoshutexefeild.text;
             NSString *signStr = [NSString stringWithFormat:@"%@%@%@",uid,tStr,@"adesxloksy13s98adv"];
    
    
             NSString  *signStrMd5  =   [WMUtil md5HexDigest:signStr];
          
            NSDictionary *parametes = nil;
            
    
          if (self.indepath.row == 2) {
                parametes = @{      @"ios" : @"1",
                                  @"ct" : @"app",
                                  @"ac" : @"my_edit",
                                   @"t" : tStr,
                                   @"uid":uid,
                                    @"qq" : wenneiStr,
                                   @"sign" :signStrMd5
                                                             
                                     };
        
          } else if (self.indepath.row == 3) {
              
              
              parametes = @{      @"ios" : @"1",
                                               @"ct" : @"app",
                                               @"ac" : @"my_edit",
                                                @"t" : tStr,
                                                @"uid":uid,
                                                 @"phone" : wenneiStr,
                                                @"sign" :signStrMd5
                                                                          
                                                  };
              
              
          } else if (self.indepath.row == 4) {
              
              parametes = @{      @"ios" : @"1",
                                                           @"ct" : @"app",
                                                           @"ac" : @"my_edit",
                                                            @"t" : tStr,
                                                            @"uid":uid,
                                                             @"email" : wenneiStr,
                                                            @"sign" :signStrMd5
                                                                                      
                                                              };
                       
                       
          } else if (self.indepath.row == 5) {
              
              
              parametes = @{      @"ios" : @"1",
              @"ct" : @"app",
              @"ac" : @"my_edit",
               @"t" : tStr,
               @"uid":uid,
                @"bank_id" : wenneiStr,
               @"sign" :signStrMd5
                                         
                 };
                       
                       
          } else if (self.indepath.row == 6) {
              
              parametes = @{      @"ios" : @"1",
                                 @"ct" : @"app",
                                 @"ac" : @"my_edit",
                                 @"t" : tStr,
                                 @"uid":uid,
                                 @"bank_user" : wenneiStr,
                                 @"sign" :signStrMd5
                                                    
                            };
                       
                       
          } else if (self.indepath.row == 7) {
              
              parametes = @{      @"ios" : @"1",
                                  @"ct" : @"app",
                                  @"ac" : @"my_edit",
                                  @"t" : tStr,
                                   @"uid":uid,
                                   @"address" : wenneiStr,
                                  @"sign" :signStrMd5
                                                            
                                    };
         
                 
                 
         }
    
    
            
            
          
            
            
        [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
                      
                     
            [MBProgressHUD hideHUD];
            NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
            if ([codeStr intValue] == 1) {
                     
               NSLog(@"%@",response);
                          
                [self.delegate shuxingshuju];
                
                          
                    
                        
             } else {
                          
               [MBProgressHUD showError:response[@"message"]];
                                        
                    
                          
          }
                      
                 
                      
        } failure:^(NSString *error) {
                     // [SVProgressHUD dismiss];
                      
                      [MBProgressHUD showSuccess:@"登录失败"];
                      [MBProgressHUD hideHUD];
                      
                      
                      
                      
        }];
    
    
    
    
    
    
}














- (void)quxiaoBut {
     [self removeFromSuperview];
    
    [self.miaoshutexefeild resignFirstResponder];
    
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    [textField resignFirstResponder];
    return  YES;
}


@end
